package com.fr.chart.plot;

import com.fr.base.background.Background;
import com.fr.base.background.IntervalColorBackground;
import com.fr.base.core.FRCoreContext;
import com.fr.base.core.util.vt.VT4FR;
import com.fr.base.core.util.vt.VT4FR.FUNC;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.GeneralInfo;
import com.fr.chart.axis.CategoryAxis;
import com.fr.chart.axis.SeriesAttrLine;
import com.fr.chart.axis.SeriesAttrMarkerType;
import com.fr.chart.axis.ValueAxis;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.glyph.CategoryAxisGlyph;
import com.fr.chart.core.glyph.CustomPlotGlyph;
import com.fr.chart.core.glyph.DateAxisGlyph;
import com.fr.chart.core.glyph.PlotGlyph;
import com.fr.chart.core.glyph.ValueAxisGlyph;
import com.fr.chart.legend.LineMarkerIcon;
import com.fr.chart.marker.Marker;
import com.fr.chart.marker.MarkerFactory;
import com.fr.data.ChartData;

public class CustomPlot extends CategoryPlot
{
  private static final long serialVersionUID = 4202124515267193546L;
  public static final int BAR_RENDERER = 1;
  public static final int LINE_RENDERER = 2;
  public static final int AREA_RENDERER = 4;
  public static final String Axis_LEFT = "LEFT";
  public static final String Axis_RIGHT = "RIGHT";
  private boolean hasSecondValueAxis = false;
  private ValueAxis secondValueAxis = new ValueAxis(4);
  private boolean isSimulation3D = true;
  private double seriesOverlapPercent = -0.15D;
  private double categoryIntervalPercent = 1.0D;
  private boolean isShowLine = true;
  private boolean isShowMarker = true;
  private boolean isLineNullValueBreak = true;
  private boolean isAreaNullValueBreak = true;

  public CustomPlot()
  {
    getSeriesCollection().setDefaultSeriesAttr(new CustomAttr());
  }

  public void setSecondValueAxis(ValueAxis paramValueAxis)
  {
    this.secondValueAxis = paramValueAxis;
  }

  public ValueAxis getSecondValueAxis()
  {
    return this.secondValueAxis;
  }

  public void setHasSecondValueAxis(boolean paramBoolean)
  {
    this.hasSecondValueAxis = paramBoolean;
  }

  public boolean hasSecondValueAxis()
  {
    return this.hasSecondValueAxis;
  }

  public void setSeriesOverlapPercent(double paramDouble)
  {
    this.seriesOverlapPercent = paramDouble;
  }

  public double getSeriesOverlapPercent()
  {
    return this.seriesOverlapPercent;
  }

  public PlotGlyph createPlotGlyph(ChartData paramChartData)
  {
    CustomPlotGlyph localCustomPlotGlyph = new CustomPlotGlyph();
    if (VT4FR.ADVANCED_CHART.support())
    {
      install4PlotGlyph(localCustomPlotGlyph, paramChartData);
      createAxisGlyph(localCustomPlotGlyph, paramChartData);
    }
    return localCustomPlotGlyph;
  }

  public void install4PlotGlyph(CustomPlotGlyph paramCustomPlotGlyph, ChartData paramChartData)
  {
    super.install4PlotGlyph(paramCustomPlotGlyph, paramChartData);
    paramCustomPlotGlyph.setSimulation3D(this.isSimulation3D);
    paramCustomPlotGlyph.setCategoryIntervalPercent(this.categoryIntervalPercent);
    paramCustomPlotGlyph.setSeriesOverlapPercent(this.seriesOverlapPercent);
    paramCustomPlotGlyph.setShowMarker(this.isShowMarker);
    paramCustomPlotGlyph.setShowLine(this.isShowLine);
    paramCustomPlotGlyph.setLineNullValueBreak(this.isLineNullValueBreak);
    paramCustomPlotGlyph.setAreaNullValueBreak(this.isAreaNullValueBreak);
  }

  private void createAxisGlyph(CustomPlotGlyph paramCustomPlotGlyph, ChartData paramChartData)
  {
    CategoryAxisGlyph localCategoryAxisGlyph;
    Object localObject;
    if ((checkDate(paramChartData)) && (this.categoryAxis.isDateAxis()))
    {
      localCategoryAxisGlyph = createDateAxisGlyph();
      double[] arrayOfDouble = getDateRange(paramChartData);
      ((DateAxisGlyph)localCategoryAxisGlyph).initMinMaxValue(arrayOfDouble[0], arrayOfDouble[1]);
    }
    else
    {
      localCategoryAxisGlyph = createCategoryAxisGlyph();
    }
    paramCustomPlotGlyph.setCategoryAxisGlyph(localCategoryAxisGlyph);
    for (int i = 0; i < paramChartData.getSeriesCount(); ++i)
    {
      CustomAttr localCustomAttr = (CustomAttr)getSeriesCollection().getSeriesAttr(i);
      if ("RIGHT".equals(localCustomAttr.getAxisPosition()))
      {
        this.hasSecondValueAxis = true;
        break;
      }
      this.hasSecondValueAxis = false;
    }
    paramCustomPlotGlyph.setHasSecondValueAxis(this.hasSecondValueAxis);
    i = 0;
    int j = paramChartData.getCategoryLabelCount();
    while (i < j)
    {
      localCategoryAxisGlyph.addCategoryLabel((paramChartData.getCategoryLabel(i) == null) ? "" : paramChartData.getCategoryLabel(i));
      ++i;
    }
    ValueAxisGlyph localValueAxisGlyph = createValueAxisGlyph();
    paramCustomPlotGlyph.setValueAxisGlyph(localValueAxisGlyph);
    localValueAxisGlyph.initMinMaxValue(getAxisMinValueFromData(paramChartData, "LEFT"), getAxisMaxValueFromData(paramChartData, "LEFT"));
    if (this.hasSecondValueAxis)
    {
      localObject = new ValueAxisGlyph(getSecondValueAxis());
      paramCustomPlotGlyph.setSecondValueAxisGlyph((ValueAxisGlyph)localObject);
      ((ValueAxisGlyph)localObject).initMinMaxValue(getAxisMinValueFromData(paramChartData, "RIGHT"), getAxisMaxValueFromData(paramChartData, "RIGHT"));
    }
    if (this.bgStagger)
    {
      localObject = new IntervalColorBackground();
      ((IntervalColorBackground)localObject).setColor(getBgColor());
      ((IntervalColorBackground)localObject).setPosition(this.valueAxis.getPosition());
      paramCustomPlotGlyph.getInfo().setBackground((Background)localObject);
    }
    paramCustomPlotGlyph.axisExtends(localCategoryAxisGlyph);
  }

  private double getAxisMinValueFromData(ChartData paramChartData, String paramString)
  {
    double d = 0.0D;
    for (int i = 0; i < paramChartData.getCategoryLabelCount(); ++i)
      for (int j = 0; j < paramChartData.getSeriesCount(); ++j)
      {
        if (paramChartData.getValueAt(j, i) == null)
          break label154:
        if ((paramString.equals("LEFT")) && (!(isSeriesUseRight(j))))
          d = (paramChartData.getValueAt(j, i).doubleValue() < d) ? paramChartData.getValueAt(j, i).doubleValue() : d;
        if ((paramString.equals("RIGHT")) && (isSeriesUseRight(j)))
          d = (paramChartData.getValueAt(j, i).doubleValue() < d) ? paramChartData.getValueAt(j, i).doubleValue() : d;
      }
    label154: return d;
  }

  private double getAxisMaxValueFromData(ChartData paramChartData, String paramString)
  {
    double d1 = 0.0D;
    if (this.isStacked)
    {
      i = 0;
      while (true)
      {
        if (i >= paramChartData.getCategoryLabelCount())
          break label318;
        double d2 = 0.0D;
        for (int k = 0; k < paramChartData.getSeriesCount(); ++k)
        {
          if (paramChartData.getValueAt(k, i) == null)
            break label128:
          if ((paramString.equals("LEFT")) && (!(isSeriesUseRight(k))))
            d2 += paramChartData.getValueAt(k, i).doubleValue();
          if ((paramString.equals("RIGHT")) && (isSeriesUseRight(k)))
            d2 += paramChartData.getValueAt(k, i).doubleValue();
        }
        label128: d1 = (d2 > d1) ? d2 : d1;
        ++i;
      }
    }
    for (int i = 0; i < paramChartData.getCategoryLabelCount(); ++i)
      for (int j = 0; j < paramChartData.getSeriesCount(); ++j)
      {
        if (paramChartData.getValueAt(j, i) == null)
          break label306:
        if ((paramString.equals("LEFT")) && (!(isSeriesUseRight(j))))
          d1 = (paramChartData.getValueAt(j, i).doubleValue() > d1) ? paramChartData.getValueAt(j, i).doubleValue() : d1;
        if ((paramString.equals("RIGHT")) && (isSeriesUseRight(j)))
          d1 = (paramChartData.getValueAt(j, i).doubleValue() > d1) ? paramChartData.getValueAt(j, i).doubleValue() : d1;
      }
    if (d1 == getAxisMinValueFromData(paramChartData, paramString))
      label306: label318: return (d1 + 10.0D);
    return d1;
  }

  private boolean isSeriesUseRight(int paramInt)
  {
    CustomAttr localCustomAttr = (CustomAttr)getSeriesCollection().getSeriesAttr(paramInt);
    return (("RIGHT".equals(localCustomAttr.getAxisPosition())) && (hasSecondValueAxis()));
  }

  protected LineMarkerIcon getLineMarkerIconByIndex(int paramInt)
  {
    LineMarkerIcon localLineMarkerIcon = new LineMarkerIcon();
    CustomAttr localCustomAttr = (CustomAttr)getSeriesCollection().getSeriesAttr(paramInt);
    if (localCustomAttr.getRenderer() == 2)
    {
      localLineMarkerIcon.setLineStyle(1);
      SeriesAttrMarkerType localSeriesAttrMarkerType = (SeriesAttrMarkerType)getSeriesCollection().getSeriesCondition(new SeriesAttrMarkerType(), paramInt);
      Marker localMarker = MarkerFactory.createIndexMarker(localSeriesAttrMarkerType.getMarkerTypeIndex());
      localMarker.setSize(localMarker.getSize() * 0.6D);
      SeriesAttrLine localSeriesAttrLine = (SeriesAttrLine)getSeriesCollection().getSeriesCondition(new SeriesAttrLine(), paramInt);
      localMarker.setColor(localSeriesAttrLine.getSeriesLineColor());
      localLineMarkerIcon.setColor(localSeriesAttrLine.getSeriesLineColor());
      localLineMarkerIcon.setMarker(localMarker);
    }
    else
    {
      dealCondition(localLineMarkerIcon, paramInt);
    }
    return localLineMarkerIcon;
  }

  public void setCategoryIntervalPercent(double paramDouble)
  {
    this.categoryIntervalPercent = paramDouble;
  }

  public double getCategoryIntervalPercent()
  {
    return this.categoryIntervalPercent;
  }

  public void setShowLine(boolean paramBoolean)
  {
    this.isShowLine = paramBoolean;
  }

  public boolean isShowLine()
  {
    return this.isShowLine;
  }

  public void setShowMarker(boolean paramBoolean)
  {
    this.isShowMarker = paramBoolean;
  }

  public boolean isShowMarker()
  {
    return this.isShowMarker;
  }

  public void setSimulation3D(boolean paramBoolean)
  {
    this.isSimulation3D = paramBoolean;
  }

  public boolean isSimulation3D()
  {
    return this.isSimulation3D;
  }

  public void setLineNullValueBreak(boolean paramBoolean)
  {
    this.isLineNullValueBreak = paramBoolean;
  }

  public boolean isLineNullValueBreak()
  {
    return this.isLineNullValueBreak;
  }

  public void setAreaNullValueBreak(boolean paramBoolean)
  {
    this.isAreaNullValueBreak = paramBoolean;
  }

  public boolean isAreaNullValueBreak()
  {
    return this.isAreaNullValueBreak;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str2;
      String str1 = paramXMLableReader.getTagName();
      if ("SecondValueAxis".equals(str1))
      {
        if (((str2 = paramXMLableReader.getAttr("class")) != null) && (str2.endsWith(".ValueAxis")))
          this.secondValueAxis = ((ValueAxis)paramXMLableReader.readXMLObject(new ValueAxis()));
      }
      else if ("Attr".equals(str1))
      {
        if ((str2 = paramXMLableReader.getAttr("value")) != null)
          this.hasSecondValueAxis = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("isShowLine")) != null)
          this.isShowLine = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("isShowMarker")) != null)
          this.isShowMarker = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("isAreaNullValueBreak")) != null)
          this.isAreaNullValueBreak = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("isLineNullValueBreak")) != null)
          this.isLineNullValueBreak = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("categoryIntervalPercent")) != null)
          this.categoryIntervalPercent = Double.valueOf(str2).doubleValue();
        if ((str2 = paramXMLableReader.getAttr("seriesOverlapPercent")) != null)
          this.seriesOverlapPercent = Double.valueOf(str2).doubleValue();
        if ((str2 = paramXMLableReader.getAttr("isSimulation3D")) != null)
          this.isSimulation3D = Boolean.valueOf(str2).booleanValue();
      }
      else if ("Plot".equals(str1))
      {
        if ((str2 = paramXMLableReader.getAttr("class")) != null)
        {
          Object localObject = new Bar2DPlot();
          try
          {
            localObject = (Plot)FRCoreContext.classForName(str2).newInstance();
          }
          catch (Exception localException)
          {
          }
          CustomAttr localCustomAttr = (CustomAttr)getSeriesCollection().getDefaultSeriesAttr();
          localCustomAttr.setRenderer((Plot)localObject);
        }
      }
      else if ("PlotMap".equals(str1))
      {
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final CustomPlot this$0;

          public void readXML()
          {
            if (paramXMLableReader.isChildNode())
            {
              int i = -1;
              if ("Entry".equals(paramXMLableReader.getTagName()))
              {
                String str;
                if ((str = paramXMLableReader.getAttr("index")) != null)
                  i = Integer.parseInt(str);
              }
              if (i != -1)
                paramXMLableReader.readXMLObject(new CustomPlot.2(this, new Integer(i)));
            }
          }

          static CustomPlot access$000(1 param1)
          {
            return param1.this$0;
          }
        });
      }
      else if ("SeriesAxisMap".equals(str1))
      {
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final CustomPlot this$0;

          public void readXML()
          {
            if ((paramXMLableReader.isChildNode()) && ("Entry".equals(paramXMLableReader.getTagName())))
            {
              String str;
              int i = -1;
              if ((str = paramXMLableReader.getAttr("index")) != null)
                i = Integer.parseInt(str);
              if (((str = paramXMLableReader.getAttr("axisPos")) != null) && (i != -1))
              {
                CustomAttr localCustomAttr1 = (CustomAttr)this.this$0.getSeriesCollection().getSeriesAttr(i);
                CustomAttr localCustomAttr2 = new CustomAttr();
                try
                {
                  localCustomAttr2 = (CustomAttr)localCustomAttr1.clone();
                }
                catch (CloneNotSupportedException localCloneNotSupportedException)
                {
                  localCloneNotSupportedException.printStackTrace();
                }
                localCustomAttr2.setAxisPosition(str);
                this.this$0.getSeriesCollection().putSeriesAttr(i, localCustomAttr2);
              }
            }
          }
        });
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Plot");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Attr").attr("value", this.hasSecondValueAxis).attr("isShowLine", this.isShowLine).attr("isShowMarker", this.isShowMarker).attr("isLineNullValueBreak", this.isLineNullValueBreak).attr("isAreaNullValueBreak", this.isAreaNullValueBreak).attr("seriesOverlapPercent", this.seriesOverlapPercent).attr("categoryIntervalPercent", this.categoryIntervalPercent).attr("isSimulation3D", this.isSimulation3D).end();
    if (this.secondValueAxis != null)
      this.secondValueAxis.writeXML(paramXMLPrintWriter, "SecondValueAxis");
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof CustomPlot))
      return false;
    CustomPlot localCustomPlot = (CustomPlot)paramObject;
    if (!(super.equals(localCustomPlot)))
      return false;
    if ((localCustomPlot.hasSecondValueAxis != this.hasSecondValueAxis) || (localCustomPlot.isAreaNullValueBreak != this.isAreaNullValueBreak) || (localCustomPlot.isLineNullValueBreak != this.isLineNullValueBreak) || (localCustomPlot.isShowLine != this.isShowLine) || (localCustomPlot.isShowMarker != this.isShowMarker) || (localCustomPlot.seriesOverlapPercent != this.seriesOverlapPercent) || (localCustomPlot.categoryIntervalPercent != this.categoryIntervalPercent) || (localCustomPlot.isSimulation3D != this.isSimulation3D))
      return false;
    return (Equals.equals(localCustomPlot.getSecondValueAxis(), getSecondValueAxis()));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    CustomPlot localCustomPlot = (CustomPlot)super.clone();
    if (this.valueAxis != null)
      localCustomPlot.valueAxis = ((ValueAxis)this.valueAxis.clone());
    return localCustomPlot;
  }
}